package ua.yandex.skipass;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Пропуск на дни
 *
 * @author WslF
 */
public class PassDays extends Pass {

    private GregorianCalendar activationDate;

    public PassDays(TypeOfPasses type) {
        super(type);
        activationDate = new GregorianCalendar();
    }

    @Override
    protected boolean couldUse() {
        if (activationDate == null) {
            return false;
        }
        Calendar curDate = new GregorianCalendar();

        switch (type) { // проверка на день недели
            case HolidayAfternoon:
            case HolidayMorning:
            case HolidayOneDay:
            case HolidayTwoDays:
                if (curDate.get(Calendar.DAY_OF_WEEK)
                        != Calendar.SUNDAY
                        && curDate.get(Calendar.DAY_OF_WEEK)
                        != Calendar.SATURDAY) {
                    return false;
                }
                break;
            default:
                if (curDate.get(Calendar.DAY_OF_WEEK)
                        == Calendar.SUNDAY
                        || curDate.get(Calendar.DAY_OF_WEEK)
                        == Calendar.SATURDAY) {
                    return false;
                }

        }

        switch (type) {
            case Morning:
                return curDate.get(Calendar.DAY_OF_YEAR)
                        == activationDate.get(Calendar.DAY_OF_YEAR)
                        && curDate.get(Calendar.HOUR_OF_DAY)
                        >= 2 * 2 * 2 * 2 + 1
                        && curDate.get(Calendar.HOUR_OF_DAY)
                        < 2 * 2 * 2 + 2 * 2 + 1;

            case Afternoon:
                return curDate.get(Calendar.DAY_OF_YEAR)
                        == activationDate.get(Calendar.DAY_OF_YEAR)
                        && curDate.get(Calendar.HOUR_OF_DAY)
                        >= 2 * 2 * 2 + 2 * 2 + 1
                        && curDate.get(Calendar.HOUR_OF_DAY)
                        < 2 * 2 * 2 * 2 + 1;

            case OneDay:
            case HolidayOneDay:
                return curDate.get(Calendar.DAY_OF_YEAR)
                        == activationDate.get(Calendar.DAY_OF_YEAR);

            case TwoDays:
            case HolidayTwoDays:
                return (curDate.get(Calendar.DAY_OF_YEAR)
                        - activationDate.get(Calendar.DAY_OF_YEAR)) < 2;

            case FiveDays:
                return (curDate.get(Calendar.DAY_OF_YEAR)
                        - activationDate.get(Calendar.DAY_OF_YEAR)) < 2 * 2 + 1;
            default:
                return false;
        }
        //return false;
    }

    @Override
    protected void use() {
    }
}
